🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / repository / src / commonMain / kotlin / org / meshtastic / core / repository / SessionManager.kt
Displaying Raw • Download
core/repository/src/commonMain/kotlin/org/meshtastic/core/repository/SessionManager.kt bf929c20f274232e0eb8ddc19b2dc82403e99e5b (bf929c20) Text, 2.90 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.repository
Tff7b72import T7ee787kotlinx.coroutines.flow.Flow
Tff7b72import T7ee787okio.ByteString
Tff7b72import T7ee787org.meshtastic.core.model.SessionStatus
T8b949e/**
* Owns per-node remote-administration session state — the session passkey the firmware embeds in every admin response
* and the timestamp it was last refreshed at.
*
* Replaces the single global passkey atomic that previously lived in `CommandSenderImpl`, which silently invalidated
* the session of node A as soon as node B responded with a different key (the multi-remote-admin bug).
*
* Lifecycle:
* - [recordSession] is called by the admin packet handler whenever an inbound admin response carries a non-empty
* `session_passkey`.
* - [getPasskey] is read on the send path to attach the appropriate per-destination key.
* - [clearAll] is called on radio teardown to prevent stale keys from surviving a reconnect.
*/
Tff7b72interface T56d364SessionManager Tb4b4b4{
T8b949e/** Record an inbound session refresh from [srcNodeNum]. No-op for empty [passkey]. */
Tff7b72fun Td2a8ffrecordSessionTb4b4b4(Te6edf3srcNodeNumTb4b4b4: Tffa657IntTb4b4b4, Te6edf3passkeyTb4b4b4: Te6edf3ByteStringTb4b4b4)
T8b949e/** Returns the most recently observed passkey for [destNum], or [ByteString.EMPTY] if none. */
Tff7b72fun Td2a8ffgetPasskeyTb4b4b4(Te6edf3destNumTb4b4b4: Tffa657IntTb4b4b4)Tb4b4b4: Te6edf3ByteString
T8b949e/** Clears all per-node session state. Call on radio disconnect / teardown. */
Tff7b72fun Td2a8ffclearAllTb4b4b4(Tb4b4b4)
T8b949e/**
* Hot stream of `srcNodeNum` values, emitted exactly once per call to [recordSession] with a non-empty passkey.
* Used by `EnsureRemoteAdminSessionUseCase` to await a session refresh from a specific node without polling.
*
* Backed by a `MutableSharedFlow` with no replay; subscribers must subscribe **before** dispatching the request
* that triggers the refresh. Exposed as a [Flow] via [kotlinx.coroutines.flow.SharedFlow.asFlow]
* (kotlinx.coroutines 1.11+) to hide the `SharedFlow` API from consumers while preserving hot-stream semantics.
*/
Tff7b72val Te6edf3sessionRefreshFlowTb4b4b4: Te6edf3FlowTff7b72<Tffa657IntTff7b72>
T8b949e/**
* Cold per-node [SessionStatus] flow. Emits the current status synchronously on subscription and re-emits whenever
* the underlying state crosses the staleness threshold.
*/
Tff7b72fun Td2a8ffobserveSessionStatusTb4b4b4(Te6edf3destNumTb4b4b4: Tffa657IntTb4b4b4)Tb4b4b4: Te6edf3FlowTff7b72<Te6edf3SessionStatusTff7b72>
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.05s